#-------------------------------[知乎：叶枝黎曼]-------------------------
#单源最短路
def SPFA(start):
    queue = [start]
    inq = [False]*(n + 1)
    dis = [float('inf')]*(n + 1)
    inq[start] = True
    dis[start] = 0
    while queue:
        curNode = queue.pop(0)
        inq[curNode] = False
        if curNode not in link.keys():
            continue
        for node in link[curNode].keys():
            if dis[curNode] + link[curNode][node] < dis[node]:
                dis[node] = dis[curNode] + link[curNode][node]
                if inq[node] == False:
                    inq[node] = True
                    queue.append(node)
    return dis

def Lin(a,b,c):
    if a not in link.keys():
        link[a] = {b:c}
    else:
        if b not in link[a].keys():
            link[a].update({b:c})
        else:
            link[a][b] = min(link[a][b],c)


n,m,s,e = map(int,input().split())
link = {}
for i in range(m):
    a,b,c = map(int,input().split())
    Lin(a,b,c)
    Lin(b,a,c)

dis = SPFA(s)
print(dis[e])
